<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app"></div>
    <template id="t1">
      <div>
        {{fullName}}
        <hr />
        <button @click="setFullName">setFullName</button>
      </div>
    </template>
    <script src="./vue.js"></script>
    <script>
      // const user = {
      //   firstName: "li",
      //   lastName: "jack",
      //   get fullName() {},
      //   set fullName(v) {},
      // };
      const vm = new Vue({
        el: "#app",
        template: "#t1",
        data: {
          firstName: "li",
          lastName: "jack",
        },
        computed: {
          // 定义计算属性
          // fullName() {
          //   return `${this.lastName} ${this.firstName}`;
          // },
          fullName: {
            get() {
              return `${this.lastName} ${this.firstName}`;
            },
            set(value) {
              [this.lastName, this.firstName] = value.split(" ");
            },
          },
        },
        methods: {
          setFullName() {
            this.fullName = "lili zhang";
          },
        },
      });

      vm.age = 20;
    </script>
  </body>
</html>
